import { loginAPI } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, data) {
      state.token = data.token
      // token持久化
      setToken(state.token)
    },
    clearUserInfo(state) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    async doLogin(store, data) {
      const res = await loginAPI(data)
      store.commit('setToken', res.data)
    }
  }
}
